/*
 * @Description: 可编辑表格 - 行内元素
 * @Date: 2023-06-06 09:44:43
 * @Author: jiao-xiao-lin
 */
import { memo } from 'react';
import { Form, Input, Select } from 'antd';

const EditableCell = ({
  editing,
  dataIndex,
  type = 'input',
  title,
  inputType,
  record,
  index,
  children,
  ...restProps
}) => {
  const renderFormItem = () => {
    let result;
    switch (type) {
      case 'input':
        result = <Input />;
        break;

      case 'select':
        result = (
          <Select
            defaultValue="lucy"
            options={[
              { value: 'jack', label: 'Jack' },
              { value: 'lucy', label: 'Lucy' },
              { value: 'Yiminghe', label: 'yiminghe' },
            ]}
          />
        );
        break;

      default:
        break;
    }

    return result;
  };

  return (
    <td {...restProps}>
      {editing ? (
        <Form.Item
          name={dataIndex}
          style={{
            margin: 0,
          }}
          rules={[
            {
              required: true,
              message: '必填',
            },
          ]}
        >
          {renderFormItem()}
        </Form.Item>
      ) : (
        children
      )}
    </td>
  );
};

export default memo(EditableCell);
